import cv2
import numpy as np
import os
from lib.utils import get_logger

logger = get_logger(__name__)

def remove_watermask(image_path, output_path = None, width_ratio=0.2, height_ratio=0.1):
    image = cv2.imread(image_path)
    height, width = image.shape[:2]
    watermask_width = int(width * width_ratio)
    watermask_height = int(height * height_ratio)
    mask = np.zeros((height, width), np.uint8)
    mask[height - watermask_height : height, width - watermask_width : width] = 255
    result = cv2.inpaint(image, mask, 3, cv2.INPAINT_TELEA)
    if output_path is None:
        base_name = os.path.splitext(image_path)[0]
        print("base_name: ", base_name)
        output_path = "no_watermask.png"
    cv2.imwrite(output_path, result)
    logger.info(f"watermask removed, output path: {output_path}")
    return output_path
